<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\helpers\IsHiddenFlagHelper;
use backend\helpers\ActionButton;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\PageSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Страницы';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container page-index">

    <h1 class="main-title"><?= Html::a('Страницы деревом', ['page/index']) ?> | <?= Html::encode($this->title) ?> списком</h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div class="action-menu action-menu__container">
        <div>
            <?= ActionButton::create('Создать страницу', 'createPage') ?>
        </div>
        <div>
            <?= ActionButton::dictionaryLink('Редиректы', 'page-redirect/index', 'browsePageRedirect');?>
        </div>
    </div>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions' => [
            'class' => 'table table-striped'
        ],
        'columns' => [
            'id',
            'title',
            //'alias',
            [
                'attribute'=>'description',
                'contentOptions' => ['style' => 'width:400px; white-space: normal;'],
            ],
            //'content:ntext',
            'path',
            'depth',
            'sort',
            [
                'attribute'=>'is_draft',
                'filter'=>IsHiddenFlagHelper::StatusList(),
                'value' => function ($model) {
                    return IsHiddenFlagHelper::statusLabel($model->is_draft);
                },
                'format' => 'raw'
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'visibleButtons' =>
                [
                    'view' => Yii::$app->user->can('browsePage'),
                    'update' => Yii::$app->user->can('updatePage'),
                    'delete' => Yii::$app->user->can('deletePage'),
                ]
            ],
        ],
    ]); ?>
</div>
